home *** CD-ROM | disk | FTP | other *** search
/ BBS in a Box 7 / BBS in a Box - Macintosh - Volume VII (BBS in a Box) (January 1993).iso / Files / Tele / C / Comet2.1.3.cpt / Comet / tftp.h < prev    next >
Text File  |  1991-02-11  |  7KB  |  207 lines

  1. /*  Copyright 1984 by the Massachusetts Institute of Technology  */
  2.  
  3. /*
  4.     Copyright Cornell University 1986.  All rights are reserved.
  5.  
  6.     As of 4/10/86:
  7.     This source file may have no changes from the M.I.T original
  8.     other than this notice; but it has been tested as part of 
  9.     Cornell's Aztec-C port.  See notice.h
  10.  
  11. */
  12.  
  13. /*  See permission and disclaimer notice in file "notice.h"  */
  14. #include    <notice.h>
  15.  
  16. /* 10/1/84 - added definition of dos_eof as control Z since <stdio.h>
  17.     no longer defines it.            <John Romkey>
  18.    11/29/84 - changed round-trip time initial estimate to 2.5 sec
  19.         to accomodate overloaded VAX unix systems.
  20.                                                  <J. H. Saltzer>  
  21.     2/28/87 kevin changed timeout times to reflect 60/ticks second on the Mac.
  22.     10/29/87 kevin made tfkill() a function 
  23. */
  24.  
  25. #include <stdio.h>
  26. #include <q.h>
  27. #include <timer.h>
  28. #include <MacTCPCommonTypes.h>
  29. #include <UDPPB.h>
  30.  
  31. /* TFTP header file contains structures of TFTP packet headers and such. */
  32.  
  33. /* read or write request packet */
  34. struct tfreq {
  35.     unsigned    tf_op;        /* would be 1 (read) or 2 (write) */
  36.     char        tf_name[20];
  37. };
  38.  
  39. /* data packet */
  40. struct tfdata {
  41.     unsigned    tf_op;        /* would be 3 */
  42.     unsigned    tf_block;
  43.     char        tf_data[512];
  44. };
  45.  
  46. /* structure of an ack packet */
  47. struct    tfack {
  48.     unsigned    tf_op;        /* would be 4 */
  49.     unsigned    tf_block;
  50. };
  51.  
  52. /* error packet */
  53. #define TFERRLEN    80
  54. struct tferr {
  55.     unsigned    tf_op;        /* would be 5 */
  56.     unsigned     tf_code;
  57.     char        tf_err[TFERRLEN]; 
  58. };
  59.  
  60. /* TFTP opcodes */
  61. #define    RRQ        1            /* read  request */
  62. #define    WRQ        2            /* write request */
  63. #define    DATA    3            /* data packet */
  64. #define    ACK        4            /* acknowledgement packet */
  65. #define    ERROR    5            /* error packet */
  66.  
  67. /* TFTP error codes */
  68. #define    ERRTXT        0        /* see the enclosed text */
  69. #define    FNOTFOUND    1        /* file not found */
  70. #define    ACCESS        2        /* access violation */
  71. #define    DISKFULL    3        /* don't even ask. */
  72. #define    ILLTFTP        4        /* illegal TFTP operation */
  73. #define    BADTID        5        /* unkown transfer ID */
  74. #define    FEXISTS        6        /* file already exists */
  75. #define    NOUSER        7        /* no such user */
  76.  
  77. /* TFTP states */
  78. #define    INIT        0
  79. #define    DATAWAIT    1
  80. #define    ACKWAIT        2
  81. #define    DEAD        3
  82. #define    TIMEOUT        4
  83. #define    RCVERR        5
  84. #define    RCVACK        6
  85. #define    RCVDATA        7
  86. #define    RCVLASTDATA    8
  87. #define    TERMINATED    9
  88.  
  89. #define    TFTPSOCK    69    /* TFTP's well known port */
  90. #define    TFTPTRIES    20    /* # of retries on packet transmission */
  91. #define    REQTRIES    4    /* # of retries on initial request */
  92. #define    REQLEN        512    /* stupid, stupid... */
  93. #define    NORMLEN        512    /* normal length of received packet */
  94.  
  95. #define MACUDPLEN    2048    /* minimum UDP buffer for MacTCP */
  96.  
  97. #define    tftp_data(p)    ((struct tfdata *)((p)))->tf_data
  98.  
  99. /* The TFTP connection structure. Contains connection info, and data for
  100.     timeout calculations. */
  101.  
  102. struct tfconn {
  103.     UDPiopb        *tf_udp;    /* udp control block for this transfer */
  104.     FILE        *tf_fd;        /* file descriptor for xfer */
  105.     char *        tf_outp;    /* last sent packet */
  106.     unsigned    tf_lastlen;    /* length of last sent pkt */
  107.     unsigned    tf_expected;    /* most recently processed block */
  108.     ip_addr        tf_host;    /* host address */
  109.     unsigned short tf_port;        /* host port # */
  110.     unsigned    tf_haveport;    /* we've got the foreign port */
  111.     timer        *tf_tm;        /* our timer */
  112.     unsigned    tf_state;    /* state of connection */
  113.     unsigned    tf_tries;    /* # of retries already done */
  114.     unsigned    tf_mode;    /* mode = IMAGE, [net]ASCII, ... */
  115.     unsigned    tf_dir;        /* direction of the transfer */
  116.     long        tf_size;    /* # of bytes transferred */
  117.     unsigned    tf_rcv;        /* # of packets received */
  118.     unsigned    tf_snt;        /* # of packets sent */
  119.     unsigned    tf_ous;        /* # of out of sequence packets */
  120.     unsigned    tf_ntmo;    /* # of timeouts */
  121.     unsigned    tf_rsnd;    /* # of resends */
  122.     long        tf_trt;        /* round trip time */
  123.     long        tf_rt;        /* current timeout */
  124.     int            tf_NR;        /* number rexmissions of this pkt */
  125.     int            tf_NR_last;    /* "    "    " of prev pkt */
  126.     int            tf_K;        /* tuning constant */
  127.     long        tf_sent;    /* time that pkt was sent */
  128.     StreamPtr    stream;        /* the MacTCP udp stream * */
  129. };
  130.  
  131. /*  Constants for round trip time estimation and retry timeout.
  132.     All calculation is done in clock ticks (at a rate of 18/second) but
  133.     only the initial estimate and the upper limit are specified in ticks;
  134.     the rest of the algorithm uses dimensionless multipliers.  */
  135.  
  136. #define    Kinit    3    /* Initial divisor for (1+1/K) estimate multiplier. */
  137. #define    Kinc    1    /* Reduce K by this if previous packet lost.  */
  138. #define    T0        180    /* 2.5 secs Initial value for round trip time estimate.  */
  139. #define    MAXTMO    720    /* 12 sec. upper limit on retry timeout timer, in ticks.  */
  140. #define    TMMULT  3    /* multiplier to get retry timeout from round trip
  141.                estimate.  */
  142.  
  143. /* TFTP randoms */
  144. #define    GET    10        /* GET file from other host to here */
  145. #define    PUT    11        /* PUT file on other host */
  146. #define    ASCII    1        /* transfer as netascii */
  147. #define    IMAGE    2        /* transfer as image */
  148. #define    TEST    3        /* test mode - diskless */
  149. #define    OCTET    4        /* octet mode - same as image */
  150.  
  151. int mtcp_tftprcv();        /* packet receive routine */
  152. int mtcp_tftptmo();        /* timeout handler */
  153. long mtcp_tfcleanup();
  154. long tftpuse();
  155. long atol();
  156.  
  157. pascal void udp_event();
  158.  
  159. extern char *tftplog;
  160. extern unsigned long cticks;
  161. extern int ntftps;
  162.  
  163. extern int tfsdata;
  164. extern int tftpdata;
  165.  
  166. extern short ipp_refnum;    /* from tcp.c */
  167. extern int closeflag;        /* from tcp.c */
  168.  
  169. extern UDPiopb tfspb;
  170. extern UDPiopb tftppb;
  171.  
  172. extern int tfs_read_req;
  173. extern int tfs_read_comp;
  174. extern int tftp_read_req;
  175. extern int tftp_read_comp;
  176.  
  177. void tfs_read_done();
  178. void tftp_read_done();
  179.  
  180. extern struct tfconn tfsconn;
  181. extern struct tfconn tftpconn;
  182.  
  183. #define min(x,y)    ((x) < (y) ? (x) : (y))
  184. #define max(x,y)    ((x) > (y) ? (x) : (y))
  185.  
  186. /* the following are trace defines, mostly unused */
  187.  
  188. #define    BUGHALT        1    /* BUGHALT on a gross applications level error
  189.                     that is detected in the network code */
  190. #define    DUMP        2    /* Do a dump of all bad incoming packets */
  191. #define    INFOMSG        4    /* Print informational messages such as packet
  192.                     received, etc. */
  193. #define    NETERR        8    /* Display net interface error messages */
  194. #define    PROTERR        16    /* Display protocol level error messages */
  195. #define    TRACE        32    /* Trace packet through protocol layers */
  196. #define NETRACE        32    /* Trace packet in link level net layer */
  197. #define INTRACE        32    /* Trace packet in internet layer  */
  198. #define TCTRACE        32    /* Transmission control (UDP, TCP) trace */
  199. #define APTRACE        128    /* Trace packet through application */
  200. #define    TMO             64    /* Print message on timeout */
  201. #define    ROUTE        128    /* turn on routing tracing */
  202. #define    TCPTRACE    256
  203.  
  204. #define    OFF    0
  205. #define    ON    1
  206.  
  207.